package com.europe.business.europebusiness.ui.view;

import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;

public class ListScrollerListener extends RecyclerView.OnScrollListener {

    int lastVisibleItemPos;

    int visibleItemCount;

    int itemCount;

    @Override
    public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
        super.onScrolled(recyclerView, dx, dy);
        LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
        lastVisibleItemPos = layoutManager.findLastVisibleItemPosition();
        visibleItemCount = layoutManager.getChildCount();
        itemCount = layoutManager.getItemCount();
    }

    @Override
    public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
        super.onScrollStateChanged(recyclerView, newState);
        if (visibleItemCount > 0 && lastVisibleItemPos == itemCount - 1 && newState == RecyclerView.SCROLL_STATE_IDLE) {
            onPageNext();
        }
    }

    public void onPageNext() {


    }
}

